﻿<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?>
<topic template="Default" lasteditedby="Geert" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd">
  <title translate="true">Validation</title>
  <keywords>
    <keyword translate="true">Data annotations</keyword>
    <keyword translate="true">Errors</keyword>
    <keyword translate="true">InfobarMessageControl</keyword>
    <keyword translate="true">Validation</keyword>
    <keyword translate="true">WarningAndErrorValidator</keyword>
    <keyword translate="true">Warnings</keyword>
  </keywords>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Validation</text></para>
    </header>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">InfoBarMessageControl</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">Ever wanted to show the details of error messages to your end-users? Then, the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> is the control to use! The control shows a summary of all business and field errors provided by bindings on objects that implement the </text><text styleclass="Normal" style="font-style:italic;" translate="true">IDataErrorInfo</text><text styleclass="Normal" translate="true"> interface.</text></para>
    <para styleclass="Normal"><image src="infobarmessagecontrol.png" scale="100.00%" styleclass="Image Caption"></image></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">In combination with the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_WarningAndErrorValidator" styleclass="Normal" translate="true">WarningAndErrorValidator</link><text styleclass="Normal" translate="true"> control, the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> can even show field and business warnings for objects that implement the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_System_ComponentModel_IDataWarningInfo" styleclass="Normal" translate="true">IDataWarningInfo</link><text styleclass="Normal" translate="true"> interface that ships with Catel.</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&lt;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">catel:InfoBarMessageControl</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&gt;</text><br/><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true"> &#160; &#160;</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&lt;!--</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true"> Actual content here </text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">--&gt;</text><br/><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&lt;/</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">catel:InfoBarMessageControl</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&gt;</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> subscribes to the Validation class. This class is responsible for showing the red border around the controls that WPF shows by default. Then, it requests the actual field error property of the data item. This is added to an internal collection of error messages, and therefore the control is able to show the errors of all bindings.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">When the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_WarningAndErrorValidator" styleclass="Normal" translate="true">WarningAndErrorValidator</link><text styleclass="Normal" translate="true"> control is found as a child control, the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> also subscribes to the events exposed by the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_WarningAndErrorValidator" styleclass="Normal" translate="true">WarningAndErrorValidator</link><text styleclass="Normal" translate="true">. The internal working of that control is explained later in this article. When a data object is subscribed via the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_WarningAndErrorValidator" styleclass="Normal" translate="true">WarningAndErrorValidator</link><text styleclass="Normal" translate="true">, the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> will also handle the warnings and business errors of that data object.</text></para>
    <para styleclass="Heading1"><text styleclass="Heading1" translate="true">WarningAndErrorValidator</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_WarningAndErrorValidator" styleclass="Normal" translate="true">WarningAndErrorValidator</link><text styleclass="Normal" translate="true"> control is not visible to the end user. The only thing this control takes care of is to forward business errors and warnings to controls that are interested in them. The only control that ships with Catel is the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true">. Thanks to the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_WarningAndErrorValidator" styleclass="Normal" translate="true">WarningAndErrorValidator</link><text styleclass="Normal" translate="true">, the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> is able to show business errors and warnings to the end user.</text></para>
    <para styleclass="Code Example"><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&lt;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">catel:WarningAndErrorValidator</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true"> Source=&quot;</text><text styleclass="Code Example" style="font-weight:bold; font-style:normal; color:#000080;" translate="true">{Binding MyObject}</text><text styleclass="Code Example" style="font-weight:normal; font-style:normal; color:#000000;" translate="true">&quot; /&gt;</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">The </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_WarningAndErrorValidator" styleclass="Normal" translate="true">WarningAndErrorValidator</link><text styleclass="Normal" translate="true"> needs to be placed inside an </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true">. The control then subscribes to all property changed events to make sure it receives all change notifications. Then, on every property change, the control checks whether the sender either implements the </text><text styleclass="Normal" style="font-style:italic;" translate="true">IDataErrorInfo</text><text styleclass="Normal" translate="true"> or </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_System_ComponentModel_IDataWarningInfo" styleclass="Normal" translate="true">IDataWarningInfo</link><text styleclass="Normal" translate="true"> interfaces.</text></para>
    <para styleclass="Normal"><text styleclass="Normal" translate="true">When an error or warning is found on the changed property, the control invokes the corresponding events so the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> can show the right information. When an error or warning no longer exists in a model, a Removed event is invoked so the </text><link displaytype="text" defaultstyle="true" type="topiclink" href="T_Catel_Windows_Controls_InfoBarMessageControl" styleclass="Normal" translate="true">InfoBarMessageControl</link><text styleclass="Normal" translate="true"> knows that the error or warning should be removed from the summary.</text></para>
  </body>
</topic>
